package com.woniuxy.microfundservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.woniuxy.bean.BillBean;
import com.woniuxy.bean.ResultBean;
import com.woniuxy.bean.regularbean.MemberAccountOutBean;
import com.woniuxy.microfundservice.dao.AppCodeDao;
import com.woniuxy.microfundservice.dao.FundPositionDao;
import com.woniuxy.microfundservice.service.MemberFundAccountService;
import com.woniuxy.microfundservice.util.DailyUpdate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.joda.time.DateTime;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * Auther: yeyang  <br/>
 * Date: 2021/4/12 0012:下午 7:40  <br/>
 * Description:
 */
@RefreshScope
@RestController
@RequestMapping(value = "/memberFund", produces = MediaType.APPLICATION_JSON_VALUE)
@Api(tags = "基金关联用户")
public class MemberFundController {

    @Resource
    private MemberFundAccountService memberFundAccountService;
    @Resource
    private FundPositionDao fundPositionDao;
    @Resource
    private AppCodeDao appCodeDao;
    @Resource
    private DailyUpdate dailyUpdate;


    @PostMapping("/fundEarning")
    @ApiOperation("基金收益")
    public ResultBean fundEarning (@RequestBody BillBean billBean) {

        MemberAccountOutBean outBean = memberFundAccountService.selectByUser(billBean.getMemberName());
        if (outBean == null) {
            return ResultBean.builder().code(200).msg("用户无购买基金").build();
        }
        return ResultBean.builder().code(200).data(outBean).build();
    }


    @PostMapping("/payThen")
    @ApiOperation("购买基金后存进redis")
    public ResultBean payThen (@RequestBody BillBean billBean) {

        return this.memberFundAccountService.sureOrderDate(billBean);
    }


    @PostMapping("/sellThen")
    @ApiOperation("赎回基金后修改数据")
    public ResultBean sellThen (@RequestBody BillBean billBean) {

        return this.memberFundAccountService.sureSellDate(billBean);
    }

    @GetMapping("/test")
    @ApiOperation("定时任务测试")
    public void test (int code) {
        if (code == 1) {
            memberFundAccountService.workDayPurchase();
        } else if (code == 2) {
            memberFundAccountService.workDaySell();
        }else if(code==4){
            String fund = appCodeDao.selectById("fund");
        }else if(code==5){
            dailyUpdate.myTask();
        }else if(code==6){
            dailyUpdate.AutoInvist();
        }else if(code==7){
            memberFundAccountService.getMoney();
        }
    }
}
